package com.aizuda.boot.modules.business.performancePlan.controller;

import com.aizuda.boot.modules.common.constant.enums.CurrencyEnum;
import com.aizuda.boot.modules.business.performancePlan.dto.EnumOptionDTO;
import com.aizuda.boot.modules.common.constant.enums.CycleTypeEnum;
import com.aizuda.boot.modules.common.constant.enums.PaymentIntervalTypeEnum;
import com.aizuda.boot.modules.common.constant.enums.PaymentTimeTypeEnum;
import com.aizuda.core.api.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 付款计划枚举选项 Controller
 */
@Slf4j
@RestController
@RequestMapping("payment-plan/enums")
@Tag(name = "付款计划枚举选项", description = "付款计划相关枚举选项接口")
public class PaymentPlanEnumController {

    @GetMapping("/payment-time-types")
    @Operation(summary = "获取付款时间类型选项", description = "返回付款时间类型的下拉框选项")
    public ApiResult<List<EnumOptionDTO>> getPaymentTimeTypes() {
        try {
            log.info("获取付款时间类型选项");

            List<EnumOptionDTO> options = Arrays.stream(PaymentTimeTypeEnum.values())
                    .map(enumValue -> new EnumOptionDTO(enumValue.getCode(), enumValue.getDescription()))
                    .collect(Collectors.toList());

            log.info("获取付款时间类型选项成功，数量: {}", options.size());
            return ApiResult.ok(options);
        } catch (Exception e) {
            log.error("获取付款时间类型选项异常", e);
            return ApiResult.failed("获取付款时间类型选项异常：" + e.getMessage());
        }
    }

    @GetMapping("/payment-interval-types")
    @Operation(summary = "获取付款时间间隔类型选项", description = "返回付款时间间隔类型的下拉框选项")
    public ApiResult<List<EnumOptionDTO>> getPaymentIntervalTypes() {
        try {
            log.info("获取付款时间间隔类型选项");

            List<EnumOptionDTO> options = Arrays.stream(PaymentIntervalTypeEnum.values())
                    .map(enumValue -> new EnumOptionDTO(enumValue.getCode(), enumValue.getDescription()))
                    .collect(Collectors.toList());

            log.info("获取付款时间间隔类型选项成功，数量: {}", options.size());
            return ApiResult.ok(options);
        } catch (Exception e) {
            log.error("获取付款时间间隔类型选项异常", e);
            return ApiResult.failed("获取付款时间间隔类型选项异常：" + e.getMessage());
        }
    }

    @GetMapping("/currency-types")
    @Operation(summary = "获取货币类型选项", description = "返回货币类型的下拉框选项")
    public ApiResult<List<EnumOptionDTO>> getCurrencyTypes() {
        try {
            log.info("获取货币类型选项");

            List<EnumOptionDTO> options = Arrays.stream(CurrencyEnum.values())
                    .map(enumValue -> new EnumOptionDTO(enumValue.getAbbreviate(), enumValue.getName()))
                    .collect(Collectors.toList());

            log.info("获取货币类型选项成功，数量: {}", options.size());
            return ApiResult.ok(options);
        } catch (Exception e) {
            log.error("获取货币类型选项异常", e);
            return ApiResult.failed("获取货币类型选项异常：" + e.getMessage());
        }
    }

    @GetMapping("/cycle-types")
    @Operation(summary = "获取周期类型选项", description = "返回周期类型的下拉框选项")
    public ApiResult<List<EnumOptionDTO>> getCycleTypes() {
        try {
            log.info("获取周期类型选项");

            List<EnumOptionDTO> options = Arrays.stream(CycleTypeEnum.values())
                    .map(enumValue -> new EnumOptionDTO(enumValue.getCode(), enumValue.getDescription()))
                    .collect(Collectors.toList());

            log.info("获取周期类型选项成功，数量: {}", options.size());
            return ApiResult.ok(options);
        } catch (Exception e) {
            log.error("获取周期类型选项异常", e);
            return ApiResult.failed("获取周期类型选项异常：" + e.getMessage());
        }
    }

}
